/*    

    bobbietalk - a visual programming environment for toy robotics

    Copyright (C) 2013  Roberto Tiella

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
package bobbietalk.gui.dialogs;

import bobbietalk.gui.blocks.parametrized.EnumTypeSpec;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author tiella
 */
public class EnumAttributePanel extends javax.swing.JPanel {

    private String attributeName;
    private EnumTypeSpec enumSpec;
    private DefaultComboBoxModel enumComboModel = new DefaultComboBoxModel();

    /**
     * Creates new form AttributePanel
     */
    public EnumAttributePanel() {
        initComponents();
    }

    public void setAttributeName(String name) {
        attributeName = name;
    }

    public String getAttributeName() {
        return attributeName;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        attributeLabel = new javax.swing.JLabel();
        valuesComboBox = new javax.swing.JComboBox();
        unitsLabel = new javax.swing.JLabel();

        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        attributeLabel.setText("jLabel1");
        add(attributeLabel);

        valuesComboBox.setModel(getEnumComboModel());
        valuesComboBox.setEditor(null);
        add(valuesComboBox);

        unitsLabel.setText("unit");
        add(unitsLabel);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel attributeLabel;
    private javax.swing.JLabel unitsLabel;
    private javax.swing.JComboBox valuesComboBox;
    // End of variables declaration//GEN-END:variables

    public void setAttributeLabel(String name) {

        attributeLabel.setText(name);

    }

    public void setAttrbuteEnumType(EnumTypeSpec enumSpec) {

        this.enumSpec = enumSpec;

        enumComboModel.removeAllElements();

        for (String l : enumSpec.getLabels()) {

            enumComboModel.addElement(l);

        }




    }

//    public void setAttributeValue(String value) {
//        
//        valueTextField.setText(value);
//        
//    }
    public String getAttributeValue() {

        return enumSpec.getValueForLabel((String) enumComboModel.getSelectedItem());

    }

    void setUnits(String units) {
        unitsLabel.setText(units);
    }

    public ComboBoxModel getEnumComboModel() {
        return enumComboModel;
    }

    public void setAttributeValue(String value) {

        enumComboModel.setSelectedItem(enumSpec.getLabelForValue(value));

    }
}
